package demo;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;

/**
 * function demo
 *
 * @author dingwen
 * 2021.05.19 11:30
 */
public class FunctionDemo {
    public static void main(String[] args) {
        Function<Integer, Integer> function1 = number -> number * 2;
        Function<Integer, Integer> function2 = FunctionDemo::test;

        Integer value1 = function1.apply(2);
        System.out.println(value1);// 4

        Integer value2 = function2.apply(3);
        System.out.println(value2);// 9

        Integer value3 = function1.andThen(function2).apply(3);
        System.out.println(value3); // 36

        // 先处理参数
        Integer value4 = function1.compose(function2).apply(3);
        System.out.println(value4); // 18

        //返回一个执行了apply()方法之后只会返回输入参数的函数对象
        Object identity = Function.identity().apply("hello");
        System.out.println(identity);


    }

    public static Integer test(Integer number) {
        return number * number;
    }


}
